import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { DictData } from '#/api/system/dict/dict-data';

import { $t } from '@vben/locales';

import { renderDictTag } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'dictLabel',
    label: $t('system.dictData.dictItem'),
  },
];

export const columns: () => VxeGridProps['columns'] = () => [
  { type: 'checkbox', width: 60 },
  {
    title: $t('system.dictData.dictLabel'),
    field: 'cssClass',
    slots: {
      default: ({ row }) => {
        const { dictValue } = row as DictData;
        return renderDictTag(dictValue, [row]);
      },
    },
  },
  {
    title: $t('system.dictData.dictValue'),
    field: 'dictValue',
  },
  {
    title: $t('system.dictData.sort'),
    field: 'sort',
  },
  {
    title: $t('common.remark'),
    field: 'remark',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: $t('common.operator'),
    width: 140,
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'id',
    label: 'id',
  },
  {
    component: 'Input',
    componentProps: {
      disabled: true,
    },
    fieldName: 'dictType',
    label: $t('system.dictType.dictType'),
  },
  {
    component: 'Input',
    fieldName: 'listClass',
    label: $t('system.dictData.listClass'),
  },
  {
    component: 'Input',
    fieldName: 'dictLabel',
    label: $t('system.dictData.dictLabel'),
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'dictValue',
    label: $t('system.dictData.dictValue'),
    rules: 'required',
  },
  {
    component: 'Textarea',
    componentProps: {
      placeholder: $t('system.dictData.cssClassPlaceHolder'),
    },
    fieldName: 'cssClass',
    formItemClass: 'items-baseline',
    help: $t('system.dictData.cssClassHelp'),
    label: $t('system.dictData.cssClass'),
  },
  {
    component: 'InputNumber',
    fieldName: 'sort',
    label: $t('system.dictData.sort'),
    rules: 'required',
  },
  {
    component: 'Textarea',
    fieldName: 'remark',
    formItemClass: 'items-baseline',
    label: $t('common.remark'),
  },
];
